package zy.blue7.common.exections;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author: blue7
 * @Date: 2021/5/11 20:21
 * @Version 1.0
 * @Description
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BusinessException extends RuntimeException {

    private CodeAndMessage codeAndMessage;

    private Object data;

    public BusinessException(String code, String message) {
        codeAndMessage = new ErrorMessage(code, message);
        data = null;
    }

    public BusinessException(String code, String message, Object data) {
        codeAndMessage = new ErrorMessage(code, message);
        this.data = data;
    }

    public String getCode() {
        if (null != codeAndMessage) {
            return codeAndMessage.getCode();
        } else
            return null;
    }

    public String getMessage() {
        if (null != codeAndMessage)
            return codeAndMessage.getMessage();
        else
            return null;
    }

}
